<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>反向或交替运行动画</title>
    <style>
        /*
        animation-direction 属性指定是向前播放、向后播放还是交替播放动画。
          animation-direction 属性可接受以下值：
            normal - 动画正常播放（向前）。默认值
            reverse - 动画以反方向播放（向后）
            alternate - 动画先向前播放，然后向后
            alternate-reverse - 动画先向后播放，然后向前
        */
        div {
            width: 100px;
            height: 100px;
            background-color: red;
            position: relative;
            animation-name: example;
            animation-duration: 4s;
            animation-iteration-count: 2;
            animation-direction: alternate;
        }
        @keyframes example {
            0%   {background-color:red; left:0px; top:0px;}
            25%  {background-color:yellow; left:200px; top:0px;}
            50%  {background-color:blue; left:200px; top:200px;}
            75%  {background-color:green; left:0px; top:200px;}
            100% {background-color:red; left:0px; top:0px;}
        }
    </style>
</head>
<body>
<div></div>
</body>
</html>